package com.waijiaojun.tpo.web.admin;

import com.waijiaojun.tpo.entity.Scenario;
import com.waijiaojun.tpo.entity.Vocabulary;
import com.waijiaojun.tpo.entity.weixin.WeixinUserInfo;
import com.waijiaojun.tpo.rest.RestClientException;
import com.waijiaojun.tpo.rest.RestResponse;
import com.waijiaojun.tpo.rest.RestServerException;
import com.waijiaojun.tpo.service.ScenarioService;
import com.waijiaojun.tpo.service.VocabularyService;
import com.waijiaojun.tpo.service.weixin.WeixinUserInfoService;
import com.waijiaojun.tpo.utils.Constants;
import com.waijiaojun.tpo.utils.JsonUtil;
import com.waijiaojun.tpo.vo.BootstrapTableDataResponse;
import com.waijiaojun.tpo.vo.admin.WeixinUserInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xvitcoder
 * Date: 12/20/12
 * Time: 5:27 PM
 */
@Controller
@RequestMapping("/admin")
public class AdminUserController {

    private static Logger logger = LoggerFactory.getLogger(AdminUserController.class);
    @Autowired
    private WeixinUserInfoService weixinUserInfoService;


    @RequestMapping("user")
    public String categoryList() {
        logger.info(Constants.prefix_in );

        return "admin/user-list";
    }

    @RequestMapping("user/list/data")
    @ResponseBody
    public BootstrapTableDataResponse<WeixinUserInfoVo> teachingListData(@RequestParam(value = "order", required = false, defaultValue = "DESC") String order,
                                                                       @RequestParam(value = "sort", required = false, defaultValue = "memb_set_id") String sort,
                                                                       @RequestParam("offset") Integer offset,
                                                                       @RequestParam("limit") Integer limit,
                                                                       @RequestParam(value = "search", required = false, defaultValue = "") String search) {
        logger.info("sort=" + sort + ", order=" + order + ", offset=" + offset + ", limit=" + limit + ", search=" + search);
        try {
            if (StringUtils.isBlank(search)) {
                search = null;
            }
            BootstrapTableDataResponse<WeixinUserInfoVo> response = weixinUserInfoService.search(offset, limit, search, order, sort);
            return response;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }


}
